package com.jeesite.modules.rt.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.rt.entity.RtDeviceUpdown;
import com.jeesite.modules.rt.service.RtDeviceUpdownService;

/**
 * rt_device_updownController
 * @author 李寒冰
 * @version 2024-10-24
 */
@Controller
@RequestMapping(value = "${adminPath}/rt/rtDeviceUpdown")
public class RtDeviceUpdownController extends BaseController {

	@Autowired
	private RtDeviceUpdownService rtDeviceUpdownService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public RtDeviceUpdown get(String id, boolean isNewRecord) {
		return rtDeviceUpdownService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("rt:rtDeviceUpdown:view")
	@RequestMapping(value = {"list", ""})
	public String list(RtDeviceUpdown rtDeviceUpdown, Model model) {
		model.addAttribute("rtDeviceUpdown", rtDeviceUpdown);
		return "modules/rt/rtDeviceUpdownList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("rt:rtDeviceUpdown:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<RtDeviceUpdown> listData(RtDeviceUpdown rtDeviceUpdown, HttpServletRequest request, HttpServletResponse response) {
		rtDeviceUpdown.setPage(new Page<>(request, response));
		Page<RtDeviceUpdown> page = rtDeviceUpdownService.findPage(rtDeviceUpdown);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("rt:rtDeviceUpdown:view")
	@RequestMapping(value = "form")
	public String form(RtDeviceUpdown rtDeviceUpdown, Model model) {
		model.addAttribute("rtDeviceUpdown", rtDeviceUpdown);
		return "modules/rt/rtDeviceUpdownForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("rt:rtDeviceUpdown:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated RtDeviceUpdown rtDeviceUpdown) {
		rtDeviceUpdownService.save(rtDeviceUpdown);
		return renderResult(Global.TRUE, text("保存rt_device_updown成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("rt:rtDeviceUpdown:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(RtDeviceUpdown rtDeviceUpdown) {
		rtDeviceUpdownService.delete(rtDeviceUpdown);
		return renderResult(Global.TRUE, text("删除rt_device_updown成功！"));
	}
	
}